﻿<UserControl x:Class="CBR.Views.RecentFileView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
			 xmlns:Fluent="clr-namespace:Fluent;assembly=Fluent"
             xmlns:Converters="clr-namespace:CBR.Components.Converters"
             xmlns:Models="clr-namespace:CBR.Core.Models;assembly=CBR.Core"
             d:DesignHeight="300" d:DesignWidth="300" 
			 Background="{DynamicResource CbrDarkBackgroundBrush}">
    <UserControl.Resources>

		<Style x:Key="CbrPinToggleButton" TargetType="{x:Type ToggleButton}">
			<Setter Property="Foreground" Value="{DynamicResource CbrForegroundBrush}"/>
			<Setter Property="Background" Value="{DynamicResource CbrBackgroundNormal}"/>
			<Setter Property="BorderBrush" Value="{DynamicResource CbrBorderBrushNormal}"/>
			<Setter Property="VerticalAlignment" Value="Stretch"/>
			<Setter Property="OverridesDefaultStyle" Value="True"/>
			<Setter Property="SnapsToDevicePixels" Value="False"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type ToggleButton}">
						<Border SnapsToDevicePixels="True"
						BorderThickness="1"
						BorderBrush="{TemplateBinding BorderBrush}" 
						Background="{TemplateBinding Background}">
							<Grid Width="32">
								<Image x:Name="imgPin" Width="16" Height="16" Source="/CBR;Component/Resources/Images/16x16/pin_no.png" />
							</Grid>
						</Border>
						<ControlTemplate.Triggers>
							<Trigger Property="IsMouseOver" Value="True">
								<Setter Property="BorderBrush" Value="{DynamicResource CbrBorderBrushHighlighted}" />
								<Setter Property="Background" Value="{DynamicResource CbrBackgroundHighlighted}" />
							</Trigger>
							<Trigger Property="IsPressed" Value="True">
								<Setter Property="Background" Value="{DynamicResource CbrBackgroundSelected}"/>
								<Setter Property="BorderBrush" Value="{DynamicResource CbrBorderBrushSelected}"/>
							</Trigger>
							<Trigger Property="IsChecked" Value="True">
								<Setter Property="Source" TargetName="imgPin" Value="/CBR;Component/Resources/Images/16x16/pin_yes.png"/>
							</Trigger>
							<Trigger Property="IsEnabled" Value="False">
								<Setter Property="Visibility" Value="Hidden"/>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
		
		<DataTemplate x:Key="RecentBookTemplate" DataType="{x:Type Models:RecentFileInfo }">
            <Grid Margin="3">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
				<Button Style="{DynamicResource CbrStandardButtonItem}" Tag="{Binding}" HorizontalAlignment="Stretch" Click="BookButton_Click">
                    <StackPanel Orientation="Horizontal" Margin="5">
                        <Image Grid.Column="0" Margin="5" Source="/CBR;Component/Resources/Images/32x32/book/book.png"></Image>
                        <StackPanel Orientation="Vertical" Grid.Column="1" Margin="5">
                            <TextBlock Foreground="Black" Text="{Binding FileName}" FontSize="12" FontWeight="Bold" />
                            <TextBlock Foreground="Black" Text="{Binding FilePath}" FontSize="10" />
                        </StackPanel>
                    </StackPanel>
                </Button>
				<ToggleButton Grid.Column="2" IsChecked="{Binding IsPined}" Margin="5" Style="{DynamicResource CbrPinToggleButton}" />
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="RecentCatalogTemplate" DataType="{x:Type Models:RecentFileInfo }">
            <Grid Margin="3">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
				<Button Style="{DynamicResource CbrStandardButtonItem}" Tag="{Binding}" HorizontalAlignment="Stretch" Click="CatalogButton_Click">
                    <StackPanel Orientation="Horizontal" Margin="5">
                        <Image Grid.Column="0" Margin="5" Source="/CBR;Component/Resources/Images/32x32/library_new.png"></Image>
                        <StackPanel Orientation="Vertical" Grid.Column="1" Margin="5">
                            <TextBlock Foreground="Black" Text="{Binding FileName}" FontSize="12" FontWeight="Bold" />
                            <TextBlock Foreground="Black" Text="{Binding FilePath}" FontSize="10" />
                        </StackPanel>
                    </StackPanel>
                </Button>
				<ToggleButton Grid.Column="2" IsChecked="{Binding IsPined}" Margin="5" Style="{StaticResource CbrPinToggleButton}" />
            </Grid>
        </DataTemplate>

    </UserControl.Resources>
    <Grid Margin="15" >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*" />
            <ColumnDefinition Width="5" />
            <ColumnDefinition Width="1*" />
        </Grid.ColumnDefinitions>
        <Grid VerticalAlignment="Stretch">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock Style="{DynamicResource CbrTitleLabel}" Margin="5" Grid.Row="1"
                       Text="{LocalizationExtension ResModul=CBR.Backstage, Key=RecentFileView.Files, DefaultValue=Recent files}" />
            <Line Style="{DynamicResource CbrDashedSeparator}" X1="0" X2="1" Grid.Row="2" VerticalAlignment="Top" 
                  Visibility="{Binding ElementName=CatalogListBox, Path=Items.Count, Converter={x:Static Converters:IntToVisibilityConverter.Instance}, ConverterParameter=true, Mode=OneWay}" />
			<ScrollViewer Style="{DynamicResource CbrScrollViewer}" CanContentScroll="True" VerticalScrollBarVisibility="Auto" Grid.Row="3">
                <ItemsControl BorderThickness="0" Margin="10,0,10,10"
                    VirtualizingStackPanel.IsVirtualizing="True"
                    Name="BookListBox" 
                    ItemsSource="{Binding RecentBooks}"
                    ItemTemplate="{StaticResource RecentBookTemplate}">
                    <ItemsControl.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.HeaderTemplate>
                                <DataTemplate>
                                <Line Style="{DynamicResource CbrDashedSeparator}" X1="0" X2="1" />
                                </DataTemplate>
                            </GroupStyle.HeaderTemplate>
                        </GroupStyle>
                    </ItemsControl.GroupStyle>
                </ItemsControl>
            </ScrollViewer>
        </Grid>

        <Line Grid.Column="1"  X1="0" Y2="1" Style="{DynamicResource CbrVerticalSeparator}" />

        <Grid Grid.Column="2" VerticalAlignment="Stretch">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock Style="{DynamicResource CbrTitleLabel}" Margin="5" Grid.Row="1"
                       Text="{LocalizationExtension ResModul=CBR.Backstage, Key=RecentFileView.Libraries, DefaultValue=Recent libraries}" />
            <Line Style="{DynamicResource CbrDashedSeparator}" X1="0" X2="1" Grid.Row="2" VerticalAlignment="Top" 
                  Visibility="{Binding ElementName=CatalogListBox, Path=Items.Count, Converter={x:Static Converters:IntToVisibilityConverter.Instance}, ConverterParameter=true, Mode=OneWay}" />
			<ScrollViewer Style="{DynamicResource CbrScrollViewer}" CanContentScroll="True" VerticalScrollBarVisibility="Auto" Grid.Row="3" Margin="0,0,0,100">
                <ItemsControl BorderThickness="0" Margin="10,0,10,10"
                VirtualizingStackPanel.IsVirtualizing="True"
                Name="CatalogListBox" 
                ItemsSource="{Binding RecentCatalogs}"
                ItemTemplate="{StaticResource RecentCatalogTemplate}" >
                <ItemsControl.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <Line Style="{DynamicResource CbrDashedSeparator}" X1="0" X2="1" />
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                    </GroupStyle>
                </ItemsControl.GroupStyle>
            </ItemsControl>
            </ScrollViewer>
        </Grid>

    </Grid>
</UserControl>
